#!/bin/bash

# build the database

DB=/var/cache/packages/db

if [ ! -d "$DB" ]; then
   echo "Database does not exist in $DB/"
   echo "use update-slackware-db to update it"
   exit 1
fi

# print dependency results

cat $DB/* | egrep -a "^fos:" | cut -d ":" -f 2- | sed -r "s@.*/@@" | sort | uniq | egrep '[.]so([.]|)' | while read FILE; do
   echo -ne "$FILE: "
   FILE="$(echo $FILE | sed -r 's/[][\.|$(){}?+*^]/\\&/g')"
   egrep -a "^fos:.*/$FILE\$" $TMPDB/* \
      | cut -d ":" -f 1 | sort | uniq | xargs -r -n 1 basename \
      | sed -r "s@-[^-]+-[^-]+-[^-]+[.]t[gx]z\$@@" | tr '\n' ',' | sed -r "s/,\$//"
   echo ""
done > /var/cache/packages/slackware-libs.txt
